﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;

namespace Proyecto_XNA
{
    class Level
    {
        private List<Texture2D> kMaps = new List<Texture2D>();
        private List<Rectangle> kRectangles = new List<Rectangle>();

        private Dictionary<string, Texture2D> kDicMaps = new Dictionary<string, Texture2D>();
        private Dictionary<string, Rectangle> kDicRect = new Dictionary<string, Rectangle>();

        private Texture2D kTexture;
        private Rectangle kRectangle;

        private List<Enemy> enemies = new List<Enemy>();

        public Player Player
        {
            get { return player; }
        }
        Player player;

        public Rectangle Rectangle
        {
            get { return kRectangle; }
            set { kRectangle = value; }
        }

        public Rectangle FloorRectangle
        {
            get { return kFloorRectangle; }
            set { kFloorRectangle = value; }
        }
        Rectangle kFloorRectangle;

        public int Score
        {
            get { return score; }
        }
        int score;

        public bool ReachedExit
        {
            get { return reachedExit; }
        }
        bool reachedExit;

        public TimeSpan TimeRemaining
        {
            get { return timeRemaining; }
        }
        TimeSpan timeRemaining;

        private const int PointsPerSecond = 5;

        // Level content.        
        public ContentManager Content
        {
            get { return content; }
        }
        ContentManager content;

        private SoundEffect exitReachedSound;

        private Vector2 start;
        private Point exit = InvalidPosition;
        private static readonly Point InvalidPosition = new Point(-1, -1);

        public void FillRectangles(Rectangle kRectangle, string sRectName)
        {
            kDicRect.Add(sRectName, kRectangle);
        }

        public Level()
        {
            
        }

        public void FillMap(IServiceProvider serviceProvider, string sMapName)
        {
            content = new ContentManager(serviceProvider, "Content");

            kTexture = Content.Load<Texture2D>(@"Maps/" + sMapName);
            kDicMaps.Add(sMapName, kTexture);
            
            start = new Vector2(0, 0);
        }

        public void DrawMap(string sMapName, string sRectName, SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(kDicMaps[sMapName], start, kDicRect[sRectName], Color.White);
        }
    }
}
